﻿using System;
using System.Collections.Generic;
using Loki.Data;
using Luna.Data.Common;

namespace Luna.Data.Crm
{
    internal class CrmDataProvider : LokiDataProvider, ICrmDataProvider
    {
        public EntityDataMapper EntityMapper { get; set; }

        public IEnumerable<IEntityData> EntitiesGetAll()
        {
            return WrapperTransactional(T => EntityMapper.GetAll(T));
        }

        public void EntityDelete(IReferenceData entityID)
        {
            WrapperTransactional(T => EntityMapper.Delete(T, entityID.PK));
        }

        public IEntityData EntityGet(IReferenceData entityID)
        {
            return WrapperTransactional(T => EntityMapper.Get(T, entityID.PK));
        }

        public void EntitySave(IEntityData entity)
        {
            WrapperTransactional(T =>
            {
                entity.LastUpdate = DateTime.Now;
                EntityMapper.Save(T, entity);
            });
        }
    }
}